package com.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.pojo.WlUser;
import com.service.WlUserFService;

@Controller("WlUserFAction")
public class WlUserFAction extends ActionSupport implements ModelDriven{
	@Resource(name="WlUserFService")
	private WlUserFService wluserFService;
	private WlUser wluser;
	private String rpwd;
	
	private String name;
	private String pwd1;
	private String pwd2;
	private String tel;
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPwd1() {
		return pwd1;
	}

	public void setPwd1(String pwd1) {
		this.pwd1 = pwd1;
	}

	public String getPwd2() {
		return pwd2;
	}

	public void setPwd2(String pwd2) {
		this.pwd2 = pwd2;
	}

	public String getTel() {
		return tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}

	public String getRpwd() {
		return rpwd;
	}

	public void setRpwd(String rpwd) {
		this.rpwd = rpwd;
	}

	public WlUserFService getWluserFService() {
		return wluserFService;
	}

	public void setWluserFService(WlUserFService wluserFService) {
		this.wluserFService = wluserFService;
	}

	public WlUser getWluser() {
		return wluser;
	}

	public void setWluser(WlUser wluser) {
		this.wluser = wluser;
	}

	@Override
	public Object getModel() {
		// TODO Auto-generated method stub
		if(wluser == null){
			wluser = new WlUser();
		}
		return wluser;
	}

	public String reg(){
		System.out.println("name========" + name);
		if(name.equals("") || pwd1.equals("") || tel.equals("")){
			return "false";
		}
		if(wluserFService.isrename(name)){
			return "rename";
		}else{
			if(wluserFService.saveUser(name,pwd1,tel)){
				return "index";
			}else{
				return "false";
			}
		}
		
	}
	
	public String login(){
		System.out.println("name========" + name);
		WlUser user = wluserFService.login(name,pwd1);
		if(user != null){
			Map<String, Object> s = ActionContext.getContext().getSession();
			s.put("user", null);
			ActionContext.getContext().getSession() .put("user",user);
			return "index";
		}else{
			return "usernull";
		}
		
	}
	
	
	
	
}
